<template>
    <div>
        <el-form 
            :inline="true"
            class="login-container"
            :rules="rules"
            :model="form"
            label-width="70px" 
            >
            <h3 class="login_title">系统登录</h3>
            <el-form-item  label="用户名" prop="username">
                <el-input  v-model="form.username"></el-input>
            </el-form-item>
            <el-form-item  label="密码" prop="password">
                <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submit">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import Mock from 'mockjs'
import Cookie  from 'js-cookie'
export default {
    data () {
        return {
            form:{
                username:'',
                password:''
            },
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码' }
                ]
            }
        }
    },
    methods: {
        submit(){
            //token信息
            const token =  Mock.Random.guid()
            //token信息存入cookie用于不同页面间的通信
            Cookie.set('token',token)
            //跳转至登陆页面
            this.$router.push({name:'home'},()=>{})
        }
    }
    
}
</script>

<style lang="less" scoped>
.login-container{
    width: 350px;
    border: 1px solid #eaeaea;
    background-color: #fff;
    border-radius: 15px;
    margin: 180px auto;
    padding: 35px 35px 15px 35px;
    box-shadow: 0 0 25px #cac6ca;
    box-sizing: border-box;
    .login_title{
        text-align: center;
        margin-bottom: 40px;
        color: #505458;
    }
    .el-input{
        width: 198px;
    }
    .el-button{
       margin-left: 105px;
       margin-top: 10px;
    }
}
</style>